package com.appbee.mock;

import com.google.web.bindery.requestfactory.shared.Receiver;
import com.google.web.bindery.requestfactory.shared.Request;
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.ServerFailure;

public class RequestMock<T> implements Request<T>
{
	private RequestContext requestContext;
	private Receiver<? super T> receiver;
	
	@Override
	public void fire()
	{
	}

	@Override
	public void fire(Receiver<? super T> receiver)
	{
		this.receiver = receiver;
	}
	
	public void doOnSuccess(T returnValue)
	{
		receiver.onSuccess(returnValue);
	}
	
	public void doOnFailure(String error)
	{
		receiver.onFailure(new ServerFailure(error));
	}

	@Override
	public RequestContext to(Receiver<? super T> receiver)
	{
		this.receiver = receiver;
		return requestContext;
	}

	@Override
	public Request<T> with(String... propertyRefs)
	{
		return this;
	}

}
